﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiAWCSearchMfgCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.TcCommands;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

public class CUiAWCSearchMfgCmd : TxButtonCommand
{
  private CApAWCSearchMFGEnabler m_enabler;

  public CUiAWCSearchMfgCmd() => this.m_enabler = new CApAWCSearchMFGEnabler();

  private bool IsValidTarget(TxObjectList selectedObjects)
  {
    if (((Collection<ITxObject>) selectedObjects).Count != 1)
      return false;
    return ((Collection<ITxObject>) selectedObjects)[0] is ITxTcOperation || ((Collection<ITxObject>) selectedObjects)[0] is TxTcProcess;
  }

  private bool CanOpenMfgSearch(TxObjectList selectedObjects)
  {
    bool flag = this.IsValidTarget(selectedObjects);
    if (!flag)
    {
      int num = (int) TxMessageBox.ShowModal(DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.SEARCH_MFG_INVALID_TARGETOP_ERROR, DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.SEARCH_MFG_COMMAND_NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
    else
    {
      using (new TxCallMessages.Collector((object) "CUiAWCSearchMfgCmd.CanOpenMfgSearch"))
      {
        flag = ((Collection<ITxObject>) selectedObjects)[0].CanBeModified;
        if (!flag)
          CApAssignmnetUtil.DisplayMessage(DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.SEARCH_MFG_TARGETOP_NOT_MODIFIABLE_ERROR);
      }
    }
    return flag;
  }

  public virtual void Execute(object cmdParams)
  {
    if (CApAWCMfgTcServices.ProductScopeIsLoaded())
    {
      TxObjectList items = TxApplication.ActiveSelection.GetItems();
      if (!this.CanOpenMfgSearch(items))
        return;
      CUiAWCMfgSearchWindow awcMfgSearchWindow = new CUiAWCMfgSearchWindow((CApAWCHostSessionManager) new CApAWCSearchMFGConnectionManager()
      {
        TargetOperation = ((Collection<ITxObject>) items)[0]
      });
      ((Window) awcMfgSearchWindow).Title = $"{base.Name} - {((Collection<ITxObject>) items)[0].Name}";
      ((Window) awcMfgSearchWindow).Show();
    }
    else
    {
      int num = (int) TxMessageBox.ShowModal(DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.SEARCH_MFG_PRODUCT_SCOPE_MISSING_ERROR, DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.SEARCH_MFG_COMMAND_NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  public virtual string Name => DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.SEARCH_MFG_COMMAND_NAME;

  public virtual string Category => DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.AWC_CATAGORY;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual string Bitmap => "TcCommands.TcNavigator.Images.SearchMfgs.bmp";

  public virtual string LargeBitmap => "TcCommands.TcNavigator.Images.SearchMfgs.png";

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("SearchMfgs");

  public virtual string Tooltip => DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.SEARCH_MFG_COMMAND_TOOLTIP;

  public virtual string Description => DnProcessSimulateCommands.TcCommands.TcNavigator.StringTable.SEARCH_MFG_COMMAND_DESCRIPTION;

  public virtual void Disconnect()
  {
    if (this.m_enabler != null)
      this.m_enabler.UnregisterFromEvents();
    base.Disconnect();
  }
}
